import request from '@/axios'
import type { ListParams, Response, Time } from '@/api/api'

interface ProductRule {
  name: string
  img: string
  money: number
  purchasing_price: number
}

interface OrderDetail extends Time {
  id: number
  store_id: number
  goods_id: number
  goods_rule_id: number
  store_order_id: number
  quantity: number
  money: string
  type: number
  order_status: number
  remark: string
  status: number
  product_name: string
  product_rule: ProductRule
}

export interface Row {
  order: Time & {
    id: number
    store_id: number
    events_id: number
    type: number
    pay_type: number
    order_status: number
    user_id: number
    no: string
    store_user_id: number
    remark: string
    status: number
    order_detail: OrderDetail[]
  }
}

export interface FormData {
  rules: {
    goods_rule_id: number
    quantity: number
  }[]
  remark: string
}
interface RoleParams {
  id: number
}

// 采购单列表
export const getListApi = (data: ListParams): Promise<Response<Row>> => {
  return request.post({ url: '/order/list', data })
}
// 详情
export const getDetailApi = (id: number): Promise<IResponse<Row>> => {
  return request.post({ url: '/order/details', data: { id } })
}

// 同意
export const passStatusApi = (params: RoleParams): Promise<Response<number[]>> => {
  return request.get({ url: '/order/pass', params })
}
// 拒绝
export const rejectStatusApi = (params: RoleParams): Promise<Response<number[]>> => {
  return request.get({ url: '/order/reject', params })
}
